// 引入 vue
import Vue from 'vue'
// 引入 vue-router
import VueRouter from 'vue-router'


// 注册 or 使用 vue-router
Vue.use(VueRouter)

/**
 * route 单个路由
 * routes 路由列表
 * router 路由实例
 */

// 创建路由表
const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        component: () => import('@/views/loginView.vue'),
    },
    {
        path: '/register',
        component: () => import('@/views/RegisterView.vue'),
    },
    {
        path: '/home',
        component: () => import('@/views/index.vue'),
    },
]
// 创建路由实例
const router = new VueRouter({
    routes
})

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push
let routerReplace = VueRouter.prototype.replace
// push
VueRouter.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function replace(location) {
    return routerReplace.call(this, location).catch(err => err)
}

// 暴露
export default router